$(function () {
  // 注册按钮
  $("#goto-register").on("click", function () {
    $("#register").show();
  });
  // 注册完成
  $("#goto-login").on("click", function () {
    $("#register").hide();
  });
  // 注册
  $("#register .layui-form").on("submit", async (e) => {
    e.preventDefault();
    let obj = {
      username: $("#register input[name=username]").val(),
      password: $("#register input[name=password]").val(),
    };
    console.log(obj);
    let res = await reqPostRegister(obj);
    localStorage.setItem("big-event-token", res.data.token);
    $("#register").hide();
    let {
      data: { status, message },
    } = res;
    if (status === 0) {
      layer.msg(message);
    }
  });
  // 登入
  $("#login .layui-form").on("submit", async function (e) {
    e.preventDefault();
    let obj = {
      username: $("#login input[name=username]").val(),
      password: $("#login input[name=password]").val(),
    };
    let res = await reqPostLogin(obj);
    localStorage.setItem("big-event-token", res.data.token);
    let {
      data: { status, message },
    } = res;
    console.log(res);
    if (res.datastatus === 0) {
      location.href = "zj.html";
    }
    if(status===0) {
        layer.msg(message)
        location.href = "zj.html";
  }
});
});
